<template>
  <div class="image-upload-step">
    <div class="upload-area">
      <el-upload
        class="upload-container"
        drag
        multiple
        :auto-upload="false"
        :on-change="handleChange"
      >
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">
          将文件拖到此处，或<em>点击上传</em>
        </div>
        <template #tip>
          <div class="el-upload__tip">
            支持上传 DICOM、NIfTI 等医学影像文件
          </div>
        </template>
      </el-upload>
    </div>

    <div class="file-list" v-if="store.imageFiles.length > 0">
      <h3>已上传文件</h3>
      <el-table :data="store.imageFiles" style="width: 100%">
        <el-table-column prop="name" label="文件名" />
        <el-table-column prop="uploadTime" label="上传时间">
          <template #default="scope">
            {{ formatDate(scope.row.uploadTime) }}
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template #default="scope">
            <el-button
              link
              type="danger"
              size="small"
              @click="handleDelete(scope.$index)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup lang="ts">
import { UploadFilled } from '@element-plus/icons-vue'
import { useWorkflowStore } from '@/stores/workflow'
import { ElMessage } from 'element-plus'

const store = useWorkflowStore()

const formatDate = (dateString: string) => {
  return new Date(dateString).toLocaleString()
}

const handleChange = (file: any) => {
  // 模拟文件上传成功
  store.addImageFile({
    id: String(Date.now()),
    name: file.name,
    path: URL.createObjectURL(file.raw)
  })
  ElMessage.success('文件上传成功！')
}

const handleDelete = (index: number) => {
  store.imageFiles.splice(index, 1)
}
</script>

<style scoped>
.image-upload-step {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.upload-area {
  display: flex;
  justify-content: center;
  padding: 20px;
}

.upload-container {
  width: 100%;
  max-width: 600px;
}

.file-list {
  flex: 1;
  background: #fff;
  padding: 20px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.file-list h3 {
  margin-bottom: 20px;
  font-size: 16px;
  color: #303133;
}

:deep(.el-upload-dragger) {
  width: 100%;
}

:deep(.el-upload__tip) {
  margin-top: 10px;
  color: #909399;
}
</style> 